'''
载入json文件
合并同一key下所有csv文件
'''

import json
import csv

f = open('file.json', 'r')
dict = json.load(f)
print(dict)
sensor_list = list(dict.keys())
print(sensor_list)
for sensor in sensor_list:
    print('正在合并%s文件' % sensor)
    w = open('/home/kyrie/master_paper/dataset/merge_file/%s.csv' % sensor, 'w', newline='')
    writer = csv.writer(w)
    for file in dict[sensor]:
        with open(file, 'r') as f:
            reader = csv.reader(f)
            i = 1
            while i <= 8:
                head_row = next(reader)
                i += 1
            for row in reader:
                writer.writerow(row)
    print('合并%s文件完成' % sensor)
